/*
 * @Author: fishroom
 * @Date: 2022-10-21 15:54:42
 * @LastEditTime: 2022-10-24 15:22:08
 * @FilePath: \koa\app\server\Sys\SysRoleMenuServer.ts
 */
import { Op } from "sequelize";
import sys_role_menu from "../../model/sys_role_menu";
class SysRoleMenuServer {
  async getRoleMenuListById(id: number) {
    return await sys_role_menu.findAll({
      where: {
        role_id: id,
      },
    });
  }
  async updateRoleMenuListById(role_id: number, menu_ids: Array<number | string>) {
    try {
      await sys_role_menu.destroy({
        where: {
          role_id,
        },
      });
      await menu_ids.forEach(async (item) => {
        await sys_role_menu.findOrCreate({
          where: {
            role_id,
            menu_id: Number(item),
          },
          defaults: {
            role_id,
            menu_id: Number(item),
          },
        });
      });
    } catch (error) {}
  }
}
export default new SysRoleMenuServer();
